{% extends "base.html" %}
{% block content %}
    <div class="navbar">
        <div class="navbar-inner">
            <a class="brand" href="#">{{ _('Items') }}</a>
            {% if current_user.is_authenticated() %}
            <a href="{{ url_for('item_create') }}" class="btn btn-primary">{{ _('Create Item') }}</a>
            {% endif %}
            <div class="btn-group pull-right clearfix">
            <button class="btn dropdown-toggle" data-toggle="dropdown">{{ _('Order by') }}
                {% if 'o' in request.args %}: {{ request.args['o'] }}{% endif %} <span class="caret"></span></button>
            <ul class="dropdown-menu">
                {# TODO: prettify #}
                {% for ordering in item_orderings %}
                    {% if 'q' in request.args %}
                        <li><a href="{{ url_for('item_index', q=request.args['q'], o=ordering) }}">{{ ordering }}</a>
                    {% else %}
                        <li><a href="{{ url_for('item_index', o=ordering) }}">{{ ordering }}</a>
                    {% endif %}
                {% endfor %}
            </ul>
        </div>
        </div>
    </div>

    {% for item in items %}
        {% include "item/item.fragment.html" %}
    {% else %}
        <div class="alert alert-info">
            {% if 'q' in request.args %}
                <p>Sorry, but no items were found matching your query:</p>
                <pre>{{ request.args['q'] }}</pre>
            {% else %}
                <p>Sorry, nothing to show here.</p>
            {% endif %}
        </div>
    {% endfor %}
    <ul class="pager">
            {% if has_more %}
                <li>
                {%  if 'q' in request.args %}
                    <a class="load-more" href="{{ url_for('item_index', q=request.args['q'], c=cursor, o=request.args.get('o', 'created (descending)')) }}">{{ _('Next Page') }}</a>
                {% else %}
                    <a class="load-more" href="{{ url_for('item_index', c=cursor, o=request.args.get('o', 'created (descending)')) }}">{{ _('Next Page') }}</a>
                {% endif %}
                </li>
            {% else %}
                <li class="disabled"><a href="#" class="load-more">No More Results</a></li>
            {% endif %}
    </ul>
    {{ ext_items }}
    {% if ext_items %}
        {% for item in ext_items %}
            {% include "item/extitem.fragment.html" %}
        {% endfor %}
    {% endif %}
{% endblock %}
